package com.yipei.business.controller;

import com.yipei.business.domain.MlTradeEntrustOrder;
import com.yipei.business.service.IMlTradeAccountService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.domain.entity.MlTradeAccount;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 交易账号Controller
 *
 * @author yipei
 * @date 2024-12-21
 */
@RestController
@RequestMapping("/business/tradeAccount")
@Api(tags = "交易账号", description = "交易账号")
public class MlTradeAccountController extends BaseController {
    @Autowired
    private IMlTradeAccountService mlTradeAccountService;

    /**
     * 查询交易账号列表
     */
    //@PreAuthorize("@ss.hasPermi('business:tradeAccount:list')")
    @ApiOperation("交易账号获取数据")
    @GetMapping("/list")
    public TableDataInfo list(MlTradeAccount mlTradeAccount) {
        startPage();
        List<MlTradeAccount> list = mlTradeAccountService.selectMlTradeAccountList(mlTradeAccount);
        return getDataTable(list);
    }

    /**
     * 导出交易账号列表
     */
    //@PreAuthorize("@ss.hasPermi('business:tradeAccount:export')")
    @ApiOperation("交易账号导出数据")
    @Log(title = "交易账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlTradeAccount mlTradeAccount) {
        List<MlTradeAccount> list = mlTradeAccountService.selectMlTradeAccountList(mlTradeAccount);
        ExcelUtil<MlTradeAccount> util = new ExcelUtil<MlTradeAccount>(MlTradeAccount.class);
        util.exportExcel(response, list, "交易账号数据");
    }

    /**
     * 获取交易账号详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:tradeAccount:query')")
    @ApiOperation("交易账号通过ID获取数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlTradeAccountService.selectMlTradeAccountById(id));
    }

    /**
     * 新增交易账号
     */
    //@PreAuthorize("@ss.hasPermi('business:tradeAccount:add')")
    @ApiOperation("交易账号新增数据")
    @Log(title = "交易账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlTradeAccount mlTradeAccount) {
        return toAjax(mlTradeAccountService.insertMlTradeAccount(mlTradeAccount));
    }

    /**
     * 修改交易账号
     */
    //@PreAuthorize("@ss.hasPermi('business:tradeAccount:edit')")
    @ApiOperation("交易账号修改数据")
    @Log(title = "交易账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlTradeAccount mlTradeAccount) {
        return toAjax(mlTradeAccountService.updateMlTradeAccount(mlTradeAccount));
    }

    /**
     * 删除交易账号
     */
    //@PreAuthorize("@ss.hasPermi('business:tradeAccount:remove')")
    @ApiOperation("交易账号删除数据")
    @Log(title = "交易账号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlTradeAccountService.deleteMlTradeAccountByIds(ids));
    }

    @ApiOperation("交易账号删除数据")
    @Log(title = "交易账号", businessType = BusinessType.DELETE)
    @GetMapping("/getOrder/{tdAcc}")
    public AjaxResult getOrder(@PathVariable String tdAcc) {
        List<MlTradeEntrustOrder> mlTradeEntrustOrders=   mlTradeAccountService.getMlTradeEntrustOrder(tdAcc);
        return AjaxResult.success(mlTradeEntrustOrders);
    }
}
